'use strict';

const path = require('path');
const root = path.resolve(__dirname, '..');
const base = path.join(root, 'src', 'stylesheets', 'base.scss');
const bundle = 'styles.css';
const build = path.join(root, 'dist');

/**
 * Compile scss from source to build.
 * Will generate sourcemaps.
 * Autoprefixer is set to: last 2 version.
 *
 * @method sass
 */
function sass(gulp, plugins) {
  return () => gulp.src(base)
    .pipe(plugins.plumber({ errorHandler: (err) => plugins.util.log('sass', err) }))
    .pipe(plugins.debug({ title: 'sass: source from' }))
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass({ precision: 10 }))
    .pipe(plugins.autoprefixer({ browser: ['last 2 version'] }))
    .pipe(plugins.sourcemaps.write('.'))
    .pipe(plugins.rename(bundle))
    .pipe(gulp.dest(build))
    .pipe(plugins.debug({ title: 'sass: build into' }))
  ;
}
module.exports = sass;
